//
//  NewsContentTableViewCell.m
//  jinritoutiao
//
//  Created by 汤环 on 2025/8/14.
//

#import "NewsContentTableViewCell.h"
#import <Masonry/Masonry.h>
#import "PopUpView.h"

@interface NewsContentTableViewCell ()
@property (nonatomic, strong) UIImageView *newsImg;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *content;
@property (nonatomic, strong) UIImageView *popUpBtn;
@property (nonatomic, strong) PopUpView *popUpView;
@end

@implementation NewsContentTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self set_UI];
        [self configUI];
        
        // cell设置为无点击状态
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        // 添加action
        self.popUpBtn.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(popUpBtnTapped)];
        [self.popUpBtn addGestureRecognizer:tapGesture];
    }
    
    return self;
}

-(void)set_UI{
    [self.contentView addSubview:self.newsImg];
    [self.contentView addSubview:self.title];
    [self.contentView addSubview:self.content];
    [self.contentView addSubview:self.popUpBtn];
}

//-(void)layoutSubviews{
//    [super layoutSubviews];
//    
//}

-(void)configUI{
    
    // 图片位置：左边距30，垂直居中
    [self.newsImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(-20);
            make.centerY.mas_equalTo(self.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(60,60));
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(20);
            make.top.mas_equalTo(20);
    }];
    
    // 文本位置：左边距70，垂直居中，给 Label 足够的高度
    [self.content mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(20);
            make.bottom.mas_equalTo(-20);
    }];
    
    [self.popUpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(self.newsImg.mas_leading).offset(-20);
            make.bottom.mas_equalTo(-20);
            make.size.mas_equalTo(CGSizeMake(12, 12));
    }];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


#pragma mark -- getter
-(UIImageView*)newsImg{
    if(!_newsImg){
        _newsImg = [[UIImageView alloc]init];
    }
    _newsImg.image = [UIImage imageNamed:@"news_default"];
    
    return _newsImg;
}

-(UILabel*)content{
    if(!_content){
        _content = [[UILabel alloc]init];
        
        // 设置 Label 的基本属性
        _content.font = [UIFont systemFontOfSize:8.0];
        _content.textColor = [UIColor blackColor];
        _content.textAlignment = NSTextAlignmentLeft;
        _content.numberOfLines = 0; // 允许多行显示
        _content.lineBreakMode = NSLineBreakByWordWrapping; // 按单词换行
        
        _content.text = @"这是content——————";
    }
    
    return _content;
}

-(UILabel*)title{
    if(!_title){
        _title = [[UILabel alloc]init];
        
        // 设置 Label 的基本属性
        _title.font = [UIFont systemFontOfSize:16.0];
        _title.textColor = [UIColor blackColor];
        _title.textAlignment = NSTextAlignmentLeft;
        _title.numberOfLines = 0; // 允许多行显示
        _title.lineBreakMode = NSLineBreakByWordWrapping; // 按单词换行
        
        _title.text = @"这是title——————";
    }
    
    return _title;
}

-(UIImageView *)popUpBtn{
    if(!_popUpBtn){
        _popUpBtn = [[UIImageView alloc]init];
        _popUpBtn.image = [UIImage imageNamed:@"homePageCell_popUpBtnImg"];
    }
    return _popUpBtn;
}

-(PopUpView *)popUpView{
    if(!_popUpView){
        _popUpView = [[PopUpView alloc]init];
        
    }
    
    return _popUpView;
}

#pragma mark -- Action
-(void)popUpBtnTapped{
    
}
@end
